<template>
  <div class="fastNavControl">
    <div class="control-section">
      <div class="control-header">
        <span>快速链接</span>
        <span @click="showBeautyBox = true">组件美化</span>
      </div>
      <div class="control-body">
        <!-- 字体配置 -->
        <fontControl
          :fontData.sync="params.params.css"
          @resetFontCss="resetFontCss"
          :showAlign="false"
        ></fontControl>
        <tabListControl
          :list="params.params.list"
          @chooseTab="chooseTab"
          @addTab="addTab"
          @reset="resetTab"
        ></tabListControl>
        <div class="tabName" v-if="choosedTab.text || choosedTab.text == ''">
          <div class="title">
            <span>选项卡标题</span>
            <span @click.stop="choosedTab.text = '选项卡'">重置</span>
          </div>
          <div class="inputBox">
            <input type="text" v-model="choosedTab.text" />
          </div>
        </div>
        <div class="tabLink" v-if="choosedTab.link || choosedTab.link == ''">
          <div class="title">
            <span>设置链接</span>
            <span @click.stop="$set(choosedTab, 'link', {})">重置</span>
          </div>
          <chooseLink
            :link="choosedTab.link || {}"
            @chooseEnd="chooseLink"
          ></chooseLink>
        </div>
      </div>
    </div>
    <!-- 组件美化 -->
    <comBeautyBox
      :showBeautyBox="showBeautyBox"
      @handleBack="showBeautyBox = false"
    >
      <div>
        <!-- 背景 -->
        <bgControl :backgroudData="params.moduleCss" sizeText="750*34"></bgControl>
        <!-- 间距圆角控制 -->
        <spaceControl
          :spaceData.sync="params.moduleCss"
          @resetSpace="resetSpace"
          @resetMp="resetMp"
        ></spaceControl>
      </div>
    </comBeautyBox>
  </div>
</template>


<script>
import { fastNav } from "@/components/DiyNew/diy/dataConfig/config.js";
import fontControl from "@/components/DiyNew/diy/baseControl/fontControl/index.vue";
import bgControl from "@/components/DiyNew/diy/baseControl/bgControl/index.vue";
import chooseLink from "@/components/DiyNew/chooseLink/index.vue";
import tabListControl from "@/components/DiyNew/diy/baseControl/tabListControl/index.vue";
import comBeautyBox from "@/components/DiyNew/diy/comBeautyBox/comBeautyBox.vue";
import spaceControl from "@/components/DiyNew/diy/baseControl/spaceControl/index.vue";
export default {
  name: "fastNavControl",
  components: {
    fontControl,
    bgControl,
    tabListControl,
    chooseLink,
    comBeautyBox,
    spaceControl,
  },
  props: {
    params: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      choosedTab: {},
      showBeautyBox: false,
      init: {},
    };
  },
  created() {
    let init = JSON.parse(JSON.stringify(fastNav));
    this.init = init;
  },
  methods: {
    resetFontCss() {
      this.$set(this.params.params, "css", this.init.params.css);
    },
    chooseTab(e) {
      console.log(e, 123);
      this.choosedTab = e;
    },
    addTab() {
      console.log("add");
      this.params.params.list.push({ text: "选项卡", link: {} });
    },
    chooseLink(e) {
      // this.$set(this.choosedTab,'link',e)
      console.log(this.choosedTab);
      this.$setWithAction(this.choosedTab, "link", e);
    },
    resetTab() {
      let obj = JSON.parse(JSON.stringify(fastNav));
      this.$set(this.params.params, "list", this.init.params.list);
    },
    // 重置圆角
    resetSpace(e) {
      let type = e.type;
      this.$set(this.params.moduleCss, type, 0);
    },
    // 重置边距
    resetMp() {
      this.$set(this.params.moduleCss, "margin", 0);
      this.$set(this.params.moduleCss, "padding", 0);
    }
  },
};
</script>


<style lang="scss" scoped>
.fastNavControl {
  height: calc(100vh - 54px);
  padding-bottom: 20px;
}
.control-section {
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  text-align: center;
  height: 100%;
  position: relative;
  .control-header {
    width: 100%;
    height: 48px;
    background: #ffffff;
    border-bottom: 1px solid #f0f2f5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    span:first-child {
      font-weight: 600;
      color: #000000;
    }
    span:last-child {
      font-size: 12px;
      color: #8c8c8c;
      cursor: pointer;
    }
  }
  .control-body {
    flex: auto;
    height: 0;
    overflow: auto;
    width: 228px;
    margin: 0 auto;
  }
}
.title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 0 12px 0;
  font-size: 12px;
  font-weight: 400;
  color: #000000;
  span:nth-child(2) {
    opacity: 0.45;
    cursor: pointer;
  }
}
.tabName {
  .inputBox {
    width: 100%;
    height: 40px;
    padding: 0 14px;
    display: flex;
    align-items: center;
    background-color: #f6f7f9;
    border-radius: 4px;
    input {
      border: none;
      outline: none;
      background-color: #f6f7f9;
    }
  }
}
</style>